//
//  RootVCOfHandRing.m
//  ProjectA_ManualGuest
//
//  Created by dingcong on 16/6/14.
//  Copyright © 2016年 丁聪. All rights reserved.
//

#import "RootVCOfHandRing.h"
#import "LoginOfVC.h"
#import "VCOfSearch.h"
#import "FlowLayoutOfTopic.h"
#import "CellOfTopic.h"
#import "VCOfHandPainted.h"
#import "VCOfOfficial.h"
#import "VCOfDiscount.h"
#import "Masonry.h"
#define tittle_view_W self.titleView.frame.size.width
#define tittle_view_H self.titleView.frame.size.height
@interface RootVCOfHandRing ()<UICollectionViewDataSource, UICollectionViewDelegate>

@property (nonatomic, retain)UICollectionView *collection;

@property (nonatomic, retain)UIView *titleView;

@property (nonatomic, retain)UIView *viewOfRedLine;

@property (nonatomic, retain)UIView *arrOfVC;
@end

@implementation RootVCOfHandRing

- (void)dealloc{
    [super dealloc];
    [_viewOfRedLine release];
    [_collection release];
    [_titleView release];
    [_arrOfVC release];
    
    
}
- (instancetype)init{
    if (self = [super init])
    {
        self.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"专题" image:[UIImage imageNamed:@"zhuanti2.png"] tag:200];
        
    }
    return self;

    
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor colorWithRed:0.0 / 256.0f  green:208.0 / 256.0f blue:252.0 / 256.0f alpha:1];
    
    [self config];
    [self creatColletionView];
    
    [self collectionconfig];
   
 
    
    
}




#pragma mark - 设置navigationItem tabbarItem控件
- (void)config{
    
    
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    
    
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.0 / 256.0f  green:208.0 / 256.0f blue:252.0 / 256.0f alpha:1];
    
    
    //    self.navigationItem.leftBarButtonItem.tintColor = [UIColor yellowColor];
    
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"11.png"] style:UIBarButtonItemStylePlain target:self action:@selector(handleSearch:)];
    
    
    [self.navigationItem setTitle:@"专题"];
    
    
    NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil];
    [self.navigationController.navigationBar setTitleTextAttributes:attributes];
    
    
    
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    
    
   
    
    [self.navigationItem.leftBarButtonItem release];
    [self.navigationItem.rightBarButtonItem release];
    
    
}

#pragma mark - navigationitem点击事件
- (void)handleSearch:(UIBarButtonItem *)search
{
    VCOfSearch *vc = [[VCOfSearch alloc]init];
    
    
    
    [self.navigationController pushViewController:vc animated:YES];
    
    [vc release];
    
    
    
    
}
#pragma mark - 创建CollectionView
- (void)creatColletionView{
    FlowLayoutOfTopic *layout = [[FlowLayoutOfTopic alloc]init];
    self.collection = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 100, SCREEN_WIDTH, SCREEN_HEIGHT - 100 - 49) collectionViewLayout:layout];
    
    layout.itemSize = CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT);
    layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    layout.minimumInteritemSpacing = 0;
    layout.minimumLineSpacing = 0;
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    self.collection.backgroundColor = [UIColor lightGrayColor];
    self.collection.pagingEnabled = YES;
    self.collection.showsHorizontalScrollIndicator = NO;
    self.collection.dataSource = self;
    [self.collection addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:nil];
    
    
    [self.collection registerClass:[CellOfTopic class] forCellWithReuseIdentifier:@"pool"];
    [self.view addSubview:self.collection];
    
    
    
    [_collection release];
    [layout release];
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    CellOfTopic *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"pool" forIndexPath:indexPath];
    
    
    return cell;
    
}
//KVO
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context
{
    
    CGFloat x = [[change objectForKey:@"new"]CGPointValue].x / 3.0f + SCREEN_WIDTH / 9.3;
    
    self.viewOfRedLine.frame = CGRectMake(x, 64 + 34.5, CGRectGetWidth(self.view.bounds)  / 6.7 - 10, 1.5);
    
    
}
#pragma mark - CollectionView嵌套TableView
- (void)collectionconfig{
    
    
    
    
    VCOfHandPainted *Painted = [[VCOfHandPainted alloc]init];
    VCOfOfficial *Official = [[VCOfOfficial alloc]init];
   VCOfDiscount *Discount = [[VCOfDiscount alloc]init];
    
    
    
    [self addChildViewController:Painted];
    [self.collection addSubview:Painted.view];
    
    [self addChildViewController:Official];
    [self.collection addSubview:Official.view];
    [self addChildViewController:Discount];
    [self.collection addSubview:Discount.view];
    
    
    
    
    
    
    [Painted.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.collection.mas_top).with.offset(-64);
        make.leading.equalTo(self.collection.mas_top).with.offset(-100);
        make.height.equalTo(self.collection.mas_height).with.offset(0);
        make.width.equalTo(self.collection.mas_width);
    }];
    
    [Official.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(Painted.view.mas_centerY);
        make.leading.equalTo(Painted.view.mas_top).with.offset(Painted.view.frame.size.width * 1 - 36);
        make.height.equalTo(Painted.view.mas_height);
        make.width.equalTo(Painted.view.mas_width);
        
    }];
    [Discount.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(Painted.view.mas_centerY);
        make.leading.equalTo(Official.view.mas_trailing).with.offset(0);
        make.height.equalTo(Painted.view.mas_height);
        make.width.equalTo(Official.view.mas_width);
        
    }];
    
    
    [Painted release];
    [Official release];
    [Discount release];
    
    
    
    
    self.titleView = [[UIView alloc]initWithFrame:CGRectMake(0, 63, SCREEN_WIDTH,  SCREEN_HEIGHT - ((self.collection.bounds.size.height) + 112))];
    //    self.titleView.backgroundColor = [UIColor purpleColor];
    [self.view addSubview:self.titleView];
    
#pragma mark - 头部button
    for (int i = 0; i < 3; i++)
    {
        
        NSMutableArray *mArrOfbuttonName = [NSMutableArray array];
        
        [mArrOfbuttonName addObject:@"好点排行榜"];
        [mArrOfbuttonName addObject:@"新手专区"];
        [mArrOfbuttonName addObject:@"折扣专区"];
       
        NSLog(@"%@", mArrOfbuttonName[i]);
        
        UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
        button.frame = CGRectMake(5 + i * tittle_view_W / 3, 71, tittle_view_W / 3 - 10 , tittle_view_H - 14);
        button.tag = 100 + 1 * i;
        [button setTitleColor:[UIColor colorWithRed:124.0f / 255.0f green:124.0f / 255.0f blue:124.0f / 255.0f alpha:1] forState:UIControlStateNormal];
        [button setTitle: mArrOfbuttonName[i] forState:UIControlStateNormal];
        
        [self.view addSubview:button];
        
    }
    
#pragma mark - 滑动头部红线
    self.viewOfRedLine = [[UIView alloc]initWithFrame:CGRectMake(26, 69 + 29, tittle_view_W / 3 - 45, 1.5)];
    [self.view addSubview:self.viewOfRedLine];
    self.viewOfRedLine.backgroundColor = [UIColor colorWithRed:0.0 / 256.0f  green:208.0 / 256.0f blue:252.0 / 256.0f alpha:1];
    
    
    
    
    [self.viewOfRedLine release];
    
#pragma mark 分割灰线
    UIView *viewOfGrayLine = [[UIView alloc]initWithFrame:CGRectMake(0, 69 + 29 + 2, tittle_view_W, 1)];
    viewOfGrayLine.backgroundColor = [UIColor colorWithRed:124.0f / 255.0f green:124.0f / 255.0f blue:124.0f / 255.0f alpha:0.4];
    
    [self.view addSubview:viewOfGrayLine];
    
    
    [self.titleView release];
    [viewOfGrayLine release];
    
    
    
    
}
#pragma mark - CollectionView Datasource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return 3;
}



@end
